/*
 * Copyright (c) 2009-2013 EvTech Project
 * All rights reserved.
 * 
 * This file is part of Game packet.
 *
 * Game packet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 *
 * Game packet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Game packet.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package fi.honkalampisaatio.game.xml;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;


public class SettingsReader {

	public static SettingsReader INSTANCE;
	
	public static SettingsReader getInstance() {
		if(INSTANCE==null) {
			INSTANCE = new SettingsReader();
		}
		return INSTANCE;
	}
	
	@SuppressWarnings({ "rawtypes" })
	public Object readSettings(String filename, Class settingsClass) 
			throws JAXBException, IOException {
		JAXBContext context = JAXBContext.newInstance(settingsClass);
		Unmarshaller um = context.createUnmarshaller();
		return um.unmarshal(new InputStreamReader(new FileInputStream(filename), "UTF-8"));
	}
	
}
